/**
 * store/modules/app.js
 */

import Vue from 'vue';
import {
    APP_LOADING,
    APP_TOAST,
    APP_SUCCESS,
    APP_FAILURE,
    APP_UPDATE_DIRECTION
} from '@/store/mutation-types';
import {
    getPlatform
} from '@/utils/tools'
import {
    apiTest
} from '@/api/app'

const client = {
    width: document.documentElement.clientWidth,
    height: document.documentElement.clientHeight,
};
const platform = getPlatform();

const state = {
    direction: '',
    appMsg: '',
    platform: platform,
    client: client,
};

const getters = {
    getterDirection: state => state.direction,
    getterPlatform: state => state.platform,
    getterClient: state => client
}

const actions = {
    showLoading({ commit }, options) {
        commit(APP_LOADING, options);
    },
    showToast({ commit }, options) {
        commit(APP_TOAST, options)
    },
    apiGetDemo(options) {
        return apiTest(options.data ? options.data : {})
    }
};
const mutations = {
    [APP_LOADING](state, data) {
    },
    [APP_TOAST](state, data) {
    },
    [APP_FAILURE](state, data) {
    },
    [APP_UPDATE_DIRECTION](state, data) {
        state.direction = data.direction
    }
}

export default {
    state,
    getters,
    actions,
    mutations,
};
